//
//  MyOrderCell.m
//  MyNewProject
//
//  Created by sun on 2019/1/28.
//  Copyright © 2019 sun. All rights reserved.
//

#import "MyOrderCell.h"
@interface MyOrderCell()

@property(nonatomic,strong)UIButton * myOrderBtn;

@property(nonatomic,strong)UIButton * lookMoreBtn;


@end
@implementation MyOrderCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self =[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.contentView.backgroundColor = [UIColor whiteColor];
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self initView];
        
    }
    return self;
    
    
}
-(void)initView
{
    
    
    [self.contentView addSubview:self.myOrderBtn];
    
    [self.contentView addSubview:self.lookMoreBtn];
    
    
    UIImageView * imageView =[[UIImageView alloc] initWithFrame:CGRectMake(0, self.lookMoreBtn.bottom, SCREEN_WIDTH, 0.5)];
    imageView.backgroundColor =SKRGBColor(237, 237, 237);
    [self.contentView addSubview:imageView];

    
  
    
    
    
    CGFloat leftAndRightBtn = 0;
    
    CGFloat btnWidth =(SCREEN_WIDTH - leftAndRightBtn)/5.0;
    
    NSArray * nameArr = @[@"待付款",@"待发货",@"待收货",@"已收货",@"已过期"];

    NSArray * imageViewArr = @[SKIMAGE_NAMED(@"notPaying"),SKIMAGE_NAMED(@"notSending"),SKIMAGE_NAMED(@"notReceiving"),SKIMAGE_NAMED(@"sendingThing"),SKIMAGE_NAMED(@"outOfDate")];
    for (int i = 0; i<5; i++) {
        NSString * totalAmtStr = nameArr[i];
        UIFont * font = SKFONT_Medium(12.0f);
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        
        button.frame = CGRectMake(leftAndRightBtn + btnWidth *i, imageView.bottom, btnWidth , 80);
        
        button.imageView.contentMode = UIViewContentModeScaleAspectFit;
        
        button.backgroundColor = [UIColor clearColor];
        
        
        [button setTitle:totalAmtStr forState:UIControlStateNormal];
        
        button.titleLabel.font = font ;
        
        [button setTitleColor:SKColorWithHex(0x909090) forState:UIControlStateNormal];
        
        [button setImage:imageViewArr[i] forState:UIControlStateNormal];
        [button setImagePosition:LXMImagePositionTop spacing:10];

        [button addTarget:self action:@selector(eventDeal:) forControlEvents:UIControlEventTouchUpInside];
        button.tag = 30000000 +i;


        [self.contentView  addSubview:button];
        
    }
    
}
-(void)eventDeal:(UIButton*)sender
{
    long count = sender.tag - 30000000;
    
    NSLog(@"----%ld----",count);
    
    if (self.myEventBlock) {
        
        self.myEventBlock(@"", count);
        
    }
}
-(UIButton*)myOrderBtn
{
    if (_myOrderBtn ==nil) {
        NSString * totalAmtStr = @"我的订单";
        UIFont * font = [UIFont fontWithName:@"PingFangSC-Medium" size:17];
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        
        
        button.frame = CGRectMake(25, 0, 120 , 50);
        
        button.imageView.contentMode = UIViewContentModeScaleAspectFit;
        
        button.backgroundColor = [UIColor clearColor];
        
        
        [button setTitle:totalAmtStr forState:UIControlStateNormal];
        
        button.titleLabel.font = font ;
        
        [button setTitleColor:SKColorWithHex(0x444444) forState:UIControlStateNormal];
//        [button setImage:[UIImage createImageWithColor:[UIColor redColor] withRect:CGSizeMake(15, 15)] forState:UIControlStateNormal];
//        [button setImagePosition:LXMImagePositionLeft spacing:10];
        button.contentHorizontalAlignment =  UIControlContentHorizontalAlignmentLeft;
      
        _myOrderBtn = button;
    }
    
    return _myOrderBtn;
    
}

-(UIButton*)lookMoreBtn
{
    if (_lookMoreBtn ==nil) {
        NSString * totalAmtStr = @"全部订单";
        UIFont * font = [UIFont fontWithName:@"PingFangSC-Medium" size:14];
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        

        button.frame = CGRectMake(SCREEN_WIDTH - 100-15, 0, 100 , 50);
        
        button.imageView.contentMode = UIViewContentModeScaleAspectFit;
        
        button.backgroundColor = [UIColor clearColor];
        
        
        [button setTitle:totalAmtStr forState:UIControlStateNormal];
        
        button.titleLabel.font = font ;
        
        [button setTitleColor:SKColorWithHex(0x888888) forState:UIControlStateNormal];
        
        [button setImage:SKIMAGE_NAMED(@"rightArrow") forState:UIControlStateNormal];
        [button setImagePosition:LXMImagePositionRight spacing:10];
        button.contentHorizontalAlignment =  UIControlContentHorizontalAlignmentRight;

        [button addTarget:self action:@selector(lookMore:) forControlEvents:UIControlEventTouchUpInside];
        _lookMoreBtn = button;
    }
    
    return _lookMoreBtn;
    
}
-(void)lookMore:(UIButton*)sender
{
    if (self.myLookMore) {
        
        self.myLookMore(@"");
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
